#include "MainWindow.h"
#include "TitleBar.h"
#include "ContextUI.h"
#include "ChatUI.h"
#include "ui_MainWindow.h"

#include "Message/TextChatMessage.h"

#include <QGridLayout>
#include <QDebug>

MainWindow* MainWindow::m_pMainWindow = nullptr;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

   // setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);


    m_pMainWindow = this;
    InitUI();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::InitUI(void){
    QGridLayout* titleLayout = new QGridLayout(ui->titleBar); //ui->mainGridLayout;
    titleLayout->addWidget(new TitleBar());
    titleLayout->setContentsMargins(0, 0, 0, 0);

    connect(ui->psbSend, SIGNAL(clicked(bool)), this, SLOT(SendMessage(bool)));

//    m_pContextUi = new ContextUI;
 //   pMainLayout->addWidget(m_pContextUi);
}

 void MainWindow::SendMessage(bool){
     QString strMessage = ui->textEdit->toPlainText();
     ui->textEdit->setText("");

     CChatMessage* txtMessage = new CTextChatMessage;
     txtMessage->SetContext(strMessage);
     ui->listWidgetChatUi->SendMessage(txtMessage);

     qDebug() << "send";
 }

void MainWindow::Test(){
//    m_pContextUi->Test();
}
